<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions">
    <span class="rst-current-version" data-toggle="rst-current-version">
        Version: {{ current_version.name }}
        <span class="fa fa-caret-down"></span>
    </span>
    <div class="rst-other-versions">
        {% set sorted_versions = [] %}
        {% for version in versions %}
            {% if version.name != 'latest' %}
            {% set parts = version.name[1:].split('.') %}
            {% set major = parts[0]|int %}
            {% set minor = parts[1]|int %}
            {% set patch = parts[2]|int %}
            {% set sort_key = '%03d.%03d.%03d'|format(major, minor, patch) %}
            {% set _ = sorted_versions.append((sort_key, version)) %}
            {% endif %}
            {% endfor %}
            {% for version in versions %}
            {% if version.name == 'latest' %}
            <a href="{{ version.url }}">{{ version.name }}</a>
            {% endif %}
            {% endfor %}
            {% for sort_key, version in sorted_versions|sort %}
            <a href="{{ version.url }}">{{ version.name }}</a>
        {% endfor %}
    </div>
</div>